package dlg.code.composite;

import dlg.code.composite.model.TreeNode;
import dlg.code.composite.model.aggregates.DecisionTree;
import dlg.code.composite.service.filter.AgeFilter;
import dlg.code.composite.service.filter.GenderFilter;
import dlg.code.composite.service.impl.DecisionEngine;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Client {

    public static void main(String[] args) {
        List<TreeNode> nodeList = genNodeList();
        Map<String, String> matterMap = genMatterMap();

        DecisionTree decisionTree = new DecisionTree();
        decisionTree.genTree(nodeList);

        DecisionEngine decisionEngine = new DecisionEngine(decisionTree);
        TreeNode decision = decisionEngine.decision(matterMap);

        System.out.println("decision = " + decision);
    }

    private static Map<String, String> genMatterMap() {
        Map<String, String> m = new HashMap<>();
        m.put("gender", "man");
        m.put("age", "26");
        return m;
    }

    private static List<TreeNode> genNodeList() {
        return Arrays.asList(
                new TreeNode(1L, null, null, "gender", false, null, null, null),
                new TreeNode(2L, 1L, "man", "age", false, null, new GenderFilter(), null),
                new TreeNode(3L, 1L, "woman", "age", false, null, new GenderFilter(), null),
                new TreeNode(4L, 2L, null, "", true, null, new AgeFilter(25, 25, "lt"), 1L),
                new TreeNode(5L, 2L, null, "", true, null, new AgeFilter(25, 25, "gte"), 2L)

//                new TreeNode(6L, 4L, null, "gender", false, null, null, null),
//                new TreeNode(7L, 5L, null, "gender", false, null, null, null),
//                new TreeNode(8L, null, null, "gender", false, null, null,null),
//                new TreeNode(9L, null, null, "gender", false, null, null, null),
//                new TreeNode(10L, null, null, "gender", false, null, null, null)
        );
    }
}
